<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ruby Summary: Ruby Study Notes - Best Ruby Guide, Ruby Tutorial</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Ruby Study Notes - Best Ruby Guide, Ruby Tutorial" />
<meta name="keywords" content="free ruby programming guide,ruby guide,free ruby programming course,best ruby guide,ruby tutorials,ruby tutorial,learn ruby,ruby,ruby on rails,ruby rails,ruby learning,ruby tutoring,learning ruby,ruby programming,ruby on rails development,ruby training" />
<meta name="Distribution" content="Global" />
<meta name="author" content="Satish Talim / Original design: Erwin Aligam - ealigam@gmail.com" />
<meta name="copyright" content="Satish Talim 2007 and beyond..." />
<meta name="verify-v1" content="rFu86se+IkbtF+bH8mgJBKwU5HnKaSd8Ghw9umXQOkM=" />
<meta name="robots" content="index,follow" />
<meta http-equiv="Expires" content="0" />
<meta name="revisit-after" content="1 days" />
<link rel="stylesheet" href="/images/NewOrange.css" type="text/css" />
<link rel="icon" type="image/ico" href="/images/favicon.ico" />
<!-- Google +1 button code -->
<link rel="canonical" href="/satishtalim/ruby_summary2.html" />
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<!-- Google Analytics code -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-59044-10']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<!-- Google Analytics code ends -->
</head>

<body>
<!-- wrap starts here -->
<div id="wrap">

    <div id="header">

        <h1 id="logo">Ruby<span class="orange">Learning.github.io</span></h1>
        <h2 id="slogan">Helping Ruby Programmers become Awesome!</h2>

    </div>

    <div id="menu">
        <ul>
            <li><a href="/" title="Home page for rubylearning.github.io">Home</a></li>
            <li><a href="/satishtalim/tutorial.html" title="Get started Learning Ruby here...">Tutorial</a></li>
            <li><a href="/download/downloads.html" title="Download this tutorial as an eBook">Downloads</a></li>
            <li><a href="/other/testimonials.html" title="People around the world who benefited from this site">Testimonials</a></li>
            <li><a href="/other/certification.html" title="Get certified in Ruby">Certification</a></li>
            <li><a href="/satishtalim/ruby_guide.html" title="Ruby Guide, Mentor">Mentor</a></li>
            <li><a href="https://blog.rubylearning.github.io/" title="Ruby blog of Learning Ruby site">Blog</a></li>
            <li><a href="/satishtalim/tutorial.html" title="Online Ruby Course">Online Course</a></li>
            <li><a href="http://ruby-challenge.rubylearning.github.io/" title="Ruby Programming Challenge for Newbies">Challenge</a></li>
            <li><a href="/satishtalim/about.html" title="Information about Satish Talim">About</a></li>
        </ul>
    </div>

    <!-- content-wrap starts here -->
    <div id="content-wrap">


            <div id="main">
                <!-- google_ad_section_start -->
                <div id="main-inner"><a name="TemplateInfo"></a>
                <h1>Ruby Summary</h1>

                <p class="post-footer align-right">
                  <strong>
                    <a href="/satishtalim/writing_own_ruby_methods.html">&lt;Writing own Ruby Methods | </a>
                    <a href="/satishtalim/tutorial.html">TOC | </a>
                    <a href="/satishtalim/ruby_ri_tool.html">Ruby ri Tool&gt;</a>
                  </strong>
                </p>

                <ol>
                  <li><em>Avoid</em> using Global scope and Global Variables. Global scope means scope that covers the entire program. Global variables are distinguished by starting with a dollar-sign ($) character. The Ruby interpreter starts up with a fairly large number of global variables already initialized. Global variables are distinguished by starting with a dollar-sign ($) character. The Ruby interpreter starts up with a fairly large number of global variables already initialized. Global variables don't mesh well with the ideals of object-oriented programming, as once you start using global variables across an application, your code is likely to become dependent on them. Because the ability to separate blocks of logic from one another is a useful aspect of object-oriented programming, <em>global variables are not favored</em>.</li>
                  <li><strong>gets</strong> (get a string) and <strong>chomp</strong> (a string method) are used to accept input from a user.</li>
                  <li><strong>gets</strong> returns a string and a '\n' character, while <strong>chomp</strong> removes this '\n'.</li>
                  <li><strong>STDOUT</strong> is a global constant which is the actual standard output stream for the program. <strong>flush</strong> flushes any buffered data within io to the underlying operating system (note that this is Ruby internal buffering only; the OS may buffer the data as well). The usage is not mandatory but recommended.</li>
                  <li>To format the output to say 2 decimal places, we can use the <strong>Kernel</strong>'s <strong>format</strong> method.</li>
                  <li>Ruby Names are used to refer to constants, variables, methods, classes, and modules. The first character of a name helps Ruby to distinguish its intended use.</li>
                  <li>Lowercase letter means the characters "a" though "z", as well as "_", the underscore. Uppercase letter means "A" though "Z", and digit means "0" through "9".</li>
                  <li>A name is an uppercase letter, lowercase letter, or an underscore, followed by Name characters: This is any combination of upper- and lowercase letters, underscore and digits.</li>
                  <li>You can use variables in your Ruby programs without any declarations. Variable name itself denotes its scope (local, global, instance, etc.).</li>
                  <li><strong>REMEMBER</strong> the way local, instance, class and global variables, constants and method names are declared.</li>
                  <li>"?", "!" and "=" are the only weird characters allowed as method name suffixes.</li>
                  <li>The Ruby convention is to use underscores to separate words in a multiword method or variable name. By convention, most constants are written in all uppercase with underscores to separate words, LIKE_THIS. Ruby class and module names are also constants, but they are conventionally written using initial capital letters and camel case, LikeThis. More examples: MyModule, MyClass, My_Constant, my_variable.</li>
                  <li>Any given variable can at different times hold references to objects of many different types.</li>
                  <li>Variables in Ruby act as "references" to objects, which undergo automatic garbage collection.</li>
                  <li>For the time being, remember that Ruby is dynamically typed and that in Ruby, everything you manipulate is an object and the results of those manipulations are themselves objects.</li>
                  <li>The basic types in Ruby are <strong>Numeric</strong> (subtypes include <strong>Fixnum</strong>, <strong>Integer</strong>, and <strong>Float</strong>), <strong>String</strong>, <strong>Array</strong>, <strong>Hash</strong>, <strong>Object</strong>, <strong>Symbol</strong>, <strong>Range</strong>, and <strong>RegExp</strong>.</li>
                  <li>For the time being, remember that you can always see what object you are in (current object) by using the special variable <strong>self</strong>.</li>
                  <li>We use <strong>def</strong> and <strong>end</strong> to declare a method. Parameters are simply a list of local variable names in parentheses.</li>
                  <li>We do not declare the return type; a method returns the value of the last statement.</li>
                  <li>It is recommended that you leave a single blank line between each method definition.</li>
                  <li>Ruby allows parentheses to be omitted from most method declarations and / or invocations. In simple cases, this results in clean-looking code. In complex cases, however, it causes syntactic ambiguities and confusion.</li>
                  <li>Methods that act as Boolean queries are often named with a trailing ?</li>
                  <li>Methods that are "dangerous," or modify the receiver, might be named with a trailing ! (Bang methods)</li>
                  <li>Ruby lets you specify default values for a method's arguments-values that will be used if the caller doesn't pass them explicitly. You do this using the assignment operator.</li>
                  <li>For now remember that there is an interpolation operator #{...}</li>
                  <li><strong>alias</strong> creates a new name that refers to an existing method. When a method is aliased, the new name refers to a copy of the original method's body. If the method is subsequently redefined, the aliased name will still invoke the original implementation.</li>
                  <li>In Ruby, we can write methods that can accept variable number of parameters.</li>
                  <li>There's no limit to the number of parameters one can pass to a method.</li>
                  <li>The sequence in which the parameters are put on to the stack are left to right.</li>
                </ol>

                <p style="background-color: #FAFAFA; padding: 5px; margin-top: 20px; font-size: 65%;"><strong>Note</strong>: The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. I have made extensive references to information, related to Ruby, available in the public domain (wikis and the blogs, articles of various <span style="font-weight: bold;" title="Click Gurus on the menu above">Ruby Gurus</span>), my acknowledgment and thanks to all of them. Much of the material on <a href="/">rubylearning.github.io</a> and in the course at <a href="http://rubylearning.org/">rubylearning.org</a> is drawn <strong>primarily</strong> from the <strong>Programming Ruby book</strong>, available from <a href="http://pragprog.com/book/ruby3/programming-ruby-1-9-2-0">The Pragmatic Bookshelf</a>.</p>

                <!-- google_ad_section_end -->
                <p class="post-footer align-right">
                  <strong>
                    <a href="/satishtalim/writing_own_ruby_methods.html">&lt;Writing own Ruby Methods | </a>
                    <a href="/satishtalim/tutorial.html">TOC | </a>
                    <a href="/satishtalim/ruby_ri_tool.html">Ruby ri Tool&gt;</a>
                  </strong>
                </p>

            </div>
            <!-- main inner ends here -->
        </div>

            <div id="rightbar">

            </div>

    <!-- content-wrap ends here -->
    </div>

<!-- wrap ends here -->
</div>

<!-- footer starts here -->
<div id="footer">
    <!-- CHANGE THE FOOTER -->
    <p>&copy; 2006-2021 <strong>rubylearning.github.io - A Ruby Tutorial</strong>&nbsp;&nbsp;Page Updated: 5th Jan. 2021 | Design: <a href="mailto:ealigam@gmail.com">Erwin Aligam</a> | Valid: <a href="http://validator.w3.org/check/referer">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/">Home</a> | <a href="/privacy.html">Privacy</a> | <a href="/sitemap.html">Sitemap</a></p>
</div>
<!-- footer ends here -->
</body>
</html>
